package com.itheima.sh.c;

import com.alibaba.fastjson.JSON;
import com.itheima.sh.b.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/ajaxJsonDemo2Servlet")
public class AjaxJsonDemo2Servlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        String name = request.getParameter("name");
        String password = request.getParameter("password");

        System.out.println(name+"---"+password);

        User user = new User();
        user.setPassword(password);
        user.setName(name);


        String jsonString = JSON.toJSONString(user);

        response.getWriter().println(jsonString);
    }
}